using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;
using System.Diagnostics;
using PuzzleDeluxe.bamboo;

namespace PuzzleDulex.bamboo
{
    class SaveHighScoreHelper
    {
        private static String storeCount = "Count";
        private static String storeTime = "Time";

        public static Score getHighScore()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;
            long time = 0;
            int count = 0;

            if (settings.Contains(storeCount))
            {
                string scoreStr = (string)settings[storeCount];
                try
                {
                    count = int.Parse(scoreStr);
                }
                catch (System.Exception ex)
                {
                    Debug.WriteLine(ex.Message.ToString());
                }

            }

            if (settings.Contains(storeTime))
            {
                string timeStr = (string)settings[storeTime];
                try
                {
                    time = long.Parse(timeStr);
                }
                catch (System.Exception ex)
                {
                    Debug.WriteLine(ex.Message.ToString());
                }

            }

            return new Score(time, count);

        }

        public static void saveHighScore(Score score)
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains(storeCount))
            {
                settings[storeCount] = score.count.ToString();
                settings.Save();

            }
            else
            {
                settings.Add(storeCount, score.count.ToString());
                settings.Save();
            }


            if (settings.Contains(storeTime))
            {
                settings[storeTime] = score.time.ToString();
                settings.Save();

            }
            else
            {
                settings.Add(storeTime, score.time.ToString());
                settings.Save();
            }



        }

    }
}
